{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "patient-estimate",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "defined \u001b[32mfunction\u001b[39m \u001b[36mcalculate\u001b[39m"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "def calculate(input: => Int) = input * 37"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "ahead-lambda",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2\n",
      "1\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "defined \u001b[32mfunction\u001b[39m \u001b[36mwhileloop\u001b[39m\r\n",
       "\u001b[36mi\u001b[39m: \u001b[32mInt\u001b[39m = \u001b[32m0\u001b[39m"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "def whileloop(condition: => Boolean)(body: => Unit): Unit = {\n",
    "    if (condition) {\n",
    "        body\n",
    "        whileloop(condition)(body)\n",
    "    }\n",
    "}\n",
    "\n",
    "var i = 2\n",
    "whileloop (i>0) {\n",
    "  println(i)\n",
    "  i -= 1\n",
    "}  // prints 2 1 这里其实是第二个参数{}，也可以用（）把body语句用，隔开写进里面"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "realistic-bradford",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Scala",
   "language": "scala",
   "name": "scala"
  },
  "language_info": {
   "codemirror_mode": "text/x-scala",
   "file_extension": ".scala",
   "mimetype": "text/x-scala",
   "name": "scala",
   "nbconvert_exporter": "script",
   "version": "2.11.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
